package com.zxjbyte.yiyi.framework.common.domain.message;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.zxjbyte.yiyi.framework.common.util.JsonUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * 消息格式定义
 *
 * @Author zhangxingjia
 * @Date 2024/7/15 17:46
 * @Version: 1.0
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StreamMessage {

    // 消息头
    private Short header;

    // 错误码
    private Short errorCode;

    // 消息体
    private Object body;

    public static StreamMessage create() {
        return new StreamMessage();
    }

    public static StreamMessage of(final Short header, final Short errorCode, final Object body) {
        final StreamMessage streamMessage = create();
        streamMessage.setHeader(header);
        streamMessage.setErrorCode(errorCode);
        streamMessage.setBody(body);
        return streamMessage;
    }

    public static StreamMessage of(final Short header, final Object body) {
        return of(header, null, body);
    }

    public String toJsonString() {
        return JsonUtil.toJsonAsString(this);
    }
}
